package com.gxa.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.gxa.common.R;
import com.gxa.entity.DistrictSysAbnormal;
import com.gxa.mapper.AbWarningStatisticsMapper;
import com.gxa.service.AbWarningStatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class AbWarningStatisticsServiceImpl implements AbWarningStatisticsService {
    @Autowired
    private AbWarningStatisticsMapper abWarningStatisticsMapper;


    /**
     * 分页查询异常预警统计表
     * @param currentPage
     * @return
     */
    @Override
    public R findAbWarningStatistics(Integer currentPage) {
        R r = new R();
        Date currentDate = new Date();
        DistrictSysAbnormal districtSysAbnormal = new DistrictSysAbnormal();
        districtSysAbnormal.setDate(currentDate);
        districtSysAbnormal.setAbnormalAlerts(abWarningStatisticsMapper.findabnormalAlerts());

        int row = abWarningStatisticsMapper.addfindabnormalAlerts(districtSysAbnormal);

        if (row > 0){
            Page page = PageHelper.startPage(currentPage,10);
            List<DistrictSysAbnormal> districtSysAbnormalList = abWarningStatisticsMapper.findabnormalAlertsList();
            int total = (int)page.getTotal();
            Map map = new HashMap();
            map.put("total",total);
            map.put("districtSysAbnormalList",districtSysAbnormalList);
            r.setCode(200);
            r.setMsg("查询成功");
            r.setData(map);

        }else {
            r.setCode(400);
            r.setMsg("查询失败");
        }
        return r;
    }

    /**
     * 根据日期查询异常预警统计表
     * @param currentPage
     * @param currentDate
     * @return
     */
    @Override
    public R findAbWarningStatisticsByDate(Integer currentPage, Date currentDate) {
        R r = new R();
        Page page = PageHelper.startPage(currentPage,10);
        List<DistrictSysAbnormal> districtSysAbnormalList = abWarningStatisticsMapper.findabnormalAlertsListByDate(currentDate);
        int total = (int)page.getTotal();
        Map map = new HashMap();
        map.put("total",total);
        map.put("districtSysAbnormalList",districtSysAbnormalList);
        r.setCode(200);
        r.setMsg("查询成功");
        r.setData(map);
        return r;
    }
}
